package DBTest;


import static org.junit.Assert.*;

import java.sql.SQLException;
import java.util.ArrayList;

import org.junit.Test;

import ServerDataBase.ServerDBUtils;

import records.GiftRecord;
import records.ReturnRecord;
import records.SalesRecord;
import records.StockInRecord;
import records.StockOutRecord;
import strategy.GoodsDiscountStrategy;
import strategy.GoodsGiftStrategy;
import strategy.TotalPriceDiscountStrategy;
import strategy.TotalPriceGiftStrategy;
import stuff.Goods;
import stuff.VIPCustomer;
import stuff.Worker;


public class ServerDB {
	ServerDBUtils handler = new ServerDBUtils();
	

	
	
	/*
	@Test//ok
	public void testGetWorkerInfo(){
		Worker worker = null;
		try {
			worker = handler.getWorkerInfo("AB2011002");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		assertEquals("AB2011002",worker.getIDNumber());
		assertEquals("Henry",worker.getName());
		assertEquals("tiancai",worker.getPassword());
		assertEquals(0,worker.getPosition());
	}
	
	@Test//ok
	public void testGetSalesRecord(){
		SalesRecord sr = null;
		try {
			sr = handler.getSalesRecord(1);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		//(saler_id,total_value,goods_list_id,date)values("AB2011001",120,1,"2012-11-11");
		assertEquals("2012-11-11",sr.getDate());
		assertEquals(1,sr.getRecordNumber());
		assertEquals("AB2011001",sr.getSalerID());
		System.out.print(sr.getSaleslist());
		assertEquals(120,sr.getTotalValue(),0.0);
	}
	
	
	@Test//ok
	public void testGetAllGoods(){
		ArrayList<Goods> list = null;
		try {
			list = handler.getAllGoods();
			for(int i = 0; i < list.size();i++){
				Goods temp = list.get(i);
				System.out.println(temp.getDescription()+"   " +temp.getID()+"  "+ temp.getPrice());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	@Test
	public void testGetAllGoodsDiscountStrategy(){
		ArrayList<GoodsDiscountStrategy> list = null;
		try {
			list = handler.getAllGoodsDiscountStrategy();
			for(int i = 0; i < list.size();i++){
				GoodsDiscountStrategy temp = list.get(i);
				System.out.println(temp.getStrategyID()+"   " +temp.getGoodsList().get(i).getDescription());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	@Test//ok
	public void testGetAllGoodsGiftStrategy(){
		ArrayList<GoodsGiftStrategy> list = null;
		try {
			list = handler.getAllGoodsGiftStrategy();
			for(int i = 0; i < list.size();i++){
				GoodsGiftStrategy temp = list.get(i);
				System.out.println(temp.getStrategyID()+"   " +temp.getGoodsList().get(i).getDescription());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	@Test//ok
	public void testGetAllTotalPriceGiftStrategy(){
		ArrayList<TotalPriceGiftStrategy> list = null;
		try {
			list = handler.getAllTotalPriceGiftStrategyStrategy();
			for(int i = 0; i < list.size();i++){
				TotalPriceGiftStrategy temp = list.get(i);
				System.out.println(temp.getStrategyID()+"   " +temp.getGiftID()+"  "+temp.getTotalPrice());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	@Test//ok
	public void testGetAllTotalPriceDiscountStrategy(){
		ArrayList<TotalPriceDiscountStrategy> list = null;
		try {
			list = handler.getAllTotalPriceDiscountStrategy();
			for(int i = 0; i < list.size();i++){
				TotalPriceDiscountStrategy temp = list.get(i);
				System.out.println(temp.getStrategyID()+"   " +temp.getDiscount()+"  "+temp.getTotalPrice());
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void testAddNewWorker(){
		Worker w1 = new Worker();
		Worker w2 = new Worker();
		ArrayList<Worker> workers = new ArrayList<Worker>();
		workers.add(w1);
		workers.add(w2);
		try {
			handler.addNewWorker(workers);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void testAddGoodsDiscountStrategy(){
		GoodsDiscountStrategy s = new GoodsDiscountStrategy();
		Goods w1 = new Goods();
		Goods w2 = new Goods();
		ArrayList<Goods> list = new ArrayList<Goods>();
		list.add(w1);
		list.add(w2);
		s.setGoodsList(list);
		try {
			handler.addGoodsDiscountStrategy(s);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	@Test
	public void testAddGoodsGiftStrategy(){
		GoodsGiftStrategy s = new GoodsGiftStrategy();
		Goods w1 = new Goods();
		Goods w2 = new Goods();
		ArrayList<Goods> list = new ArrayList<Goods>();
		list.add(w1);
		list.add(w2);
		s.setGoodsList(list);
		try {
			handler.addGoodsGiftStrategy(s);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	@Test
	public void testAddTotalPriceDiscountStrategy(){
		TotalPriceDiscountStrategy s = new TotalPriceDiscountStrategy();
		
		try {
			handler.addTotalPriceDiscountStrategy(s);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	@Test
	public void testAddTotalPriceGiftStrategy(){
		TotalPriceGiftStrategy s = new TotalPriceGiftStrategy();		
		try {
			handler.addTotalPriceGiftStrategy(s);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}


	@Test
	public void testChangeGoodsDiscount(){	
		try {		
			handler.changeGoodsDiscount("2", 0.5, 5);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}	
	@Test
	public void testChangeGoodsSpecDate(){	
		try {		
			handler.changeGoodsSpecDate("2","2011-04-04","2012-12-22");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void testchangeGoodsGift(){	
		try {		
			handler.changeGoodsGift("2", "2");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	@Test//ok
	public void testAddVIP(){
		VIPCustomer vip = new VIPCustomer();
		try {
			handler.addVIP(vip);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	@Test//OK
	public void testAddReturnedGoods(){
		ArrayList<Goods> list = new ArrayList<Goods>();
		Goods g1;
		Goods g2;
		try {
			g1 = handler.getGoodsInfo("1");
			g2 = handler.getGoodsInfo("2");
			g1.setNumber(3);
			g2.setNumber(5);
			list.add(g1);
			list.add(g2);
			handler.addReturnedGoods(list);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	@Test//ok
	public void testAddSalesRecord(){
		SalesRecord sr = new SalesRecord();
		ArrayList<Goods> list = new ArrayList<Goods>();
		Goods g1;
		Goods g2;
		try {
			g1 = handler.getGoodsInfo("1");
			g2 = handler.getGoodsInfo("2");
			list.add(g1);
			list.add(g2);
			sr.setSaleslist(list);
			handler.addSalesRecord(sr);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	@Test//ok
	public void testAddReturnRecord(){
		ReturnRecord rr = new ReturnRecord();
		ArrayList<Goods> list = new ArrayList<Goods>();
		Goods g1;
		Goods g2;
		try {
			g1 = handler.getGoodsInfo("2");
			g2 = handler.getGoodsInfo("1");
			list.add(g1);
			list.add(g2);
			rr.setSaleslist(list);
			handler.addReturnRecord(rr);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	@Test
	public void testAddStockIn(){
		StockInRecord sInRecord = new StockInRecord();
		ArrayList<Goods> list = new ArrayList<Goods>();
		Goods g1;
		Goods g2;
		try {
			g1 = handler.getGoodsInfo("2");
			g2 = handler.getGoodsInfo("1");
			list.add(g1);
			list.add(g2);
			sInRecord.setStockInList(list);
			handler.addStockIn(sInRecord);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	@Test
	public void testAddStockOut(){
		StockOutRecord sInRecord = new StockOutRecord();
		ArrayList<Goods> list = new ArrayList<Goods>();
		Goods g1;
		Goods g2;
		try {
			g1 = handler.getGoodsInfo("2");
			g2 = handler.getGoodsInfo("1");
			list.add(g1);
			list.add(g2);
			sInRecord.setStockInList(list);
			handler.addStockOut(sInRecord);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	@Test
	public void testDeleteGoods(){
		ArrayList<Goods> list = new ArrayList<Goods>();
		Goods g1;
		Goods g2;
		try {
			g1 = handler.getGoodsInfo("1");
			g2 = handler.getGoodsInfo("2");
			g1.setNumber(3);
			g2.setNumber(5);
			list.add(g1);
			list.add(g2);
			handler.deleteGoods(list);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	

	
	@Test
	public void testexport(){
		try {
			handler.exportSQLFile("E:/");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	@Test
	public void testimport(){
		try {

			handler.importSQLFile(null);

			handler.importSQLFile("e:/");

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}*/
	@Test
	public void testimport(){
		try {
			System.out.print(handler.deleteGoodsGiftStrategy(1));
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
